// pages/mysport/daka/daka.js
var util = require("../../../utils/util.js")
const gd = getApp().globalData;
const net = require('../../../utils/net.js');
var posting = false;
var dialog = null;
var calendar =null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:"",
    month:"",
    day:0,
    search_month:""
  },
  changeDay(e,option){
    this.setData({
      search_month: e.detail.year + "-" +(e.detail.month > 9 ? e.detail.month : "0" + e.detail.month),
      month:e.detail.month
    })
    this.getpunch();
  },
  getpunch() {
    if (posting) return;
    posting = true;
    var that = this;
    wx.showLoading({})
    net.request({
      url: '/PunchList',
      data: {
        shop_id: gd.shop_id,
        member_id: gd.id,
        search_month: that.data.search_month
      }, success(res) {
        var dt = res.data;
        if (dt.flag) {
          var tmplist = dt.data;
          that.setData({
            day: tmplist.length||0
          })
          calendar.pointDate(tmplist);
        } else {
          dialog.showDialog({
            msg: dt.msg
          })
        }
      }, fail(res) {

      }, complete() {
        posting = false;
        wx.hideLoading();
        wx.stopPullDownRefresh();
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(gd);
    var date = new Date();
    var month = date.getMonth() + 1;
    this.setData({
      search_month: date.getFullYear() + "-" + (month > 9 ? month : "0"+month),
      month: (date.getMonth() + 1)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    dialog = this.selectComponent("#dialog");
    calendar = this.selectComponent("#calendar");
    this.getpunch();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getpunch();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})